import {Component} from 'react';
import React from 'react';
import {connect} from 'umi';
import HighPerformTable from '@/components/HighPerformTable';
import {PlusOutlined} from '@ant-design/icons';
import {Button} from 'antd';
import APIS from '@/apis';

class ArticleTagPage extends Component<any, any> {
  actionRef: any;

  requestGetData(
    params: {
      pageSize?: number;
      current?: number;
    },
    sorter: {
      [key: string]: 'ascend' | 'descend';
    },
    filter: {
      [key: string]: React.ReactText[];
    },
  ) {
    return APIS.NewsAPI.GetTagList({...params, sorter, filter});
  }

  handleUpdateModalVisible(value: boolean) {
  }

  clomns: any = [
    {
      title: '名称',
      dataIndex: 'tag',
      rules: [
        {
          required: true,
          message: '名称为必填项',
        },
      ],
    },
    {
      title: '描述',
      dataIndex: 'description',
    },
    {
      title: '更新时间',
      dataIndex: 'updatedTime',
      hideInForm: true,
    },
  ];

  render() {
    return (
      <div>
        <HighPerformTable<any>
          columns={this.clomns}
          requestGetData={this.requestGetData.bind(this)}
          ref={(ref) => (this.actionRef = ref)}
          handleChangeState={(data, state) => {
            return APIS.NewsAPI.ChangeTagState({id: data.id, state: state === true ? 1 : 0})
          }}
          onClickUpdate={record => this.actionRef.handleUpdateModalVisible(true, record)}
          handleUpdate={record => {
            return APIS.NewsAPI.UpdateTag(record)
          }}
          handleDelete={id => {
            return APIS.NewsAPI.DeleteTag({id})
          }}
          toolBarRender={() => [
            <Button type="primary" onClick={() => this.actionRef.handleModalVisible(true)}>
              <PlusOutlined/> 新增标签
            </Button>,
          ]}
          handleAdd={data => {
            return APIS.NewsAPI.CreateNewTag({tag: data.tag, description: data.description, type: 6})
          }}
        />
      </div>
    );
  }
}

export default connect()(ArticleTagPage);
